package com.fujimana.rockincat.restree.bytecode;

import java.io.DataInputStream;
import java.io.IOException;

public final class ClassFile {
	ConstPool constPool;
	int thisClass;
	String className;

	public String getClassName() {
		return className;
	}
	
	public ClassFile(DataInputStream in) throws IOException {
		read(in);
	}

	private void read(DataInputStream in) throws IOException {
		int magic = in.readInt();
		if (magic != 0xCAFEBABE) {
			return;
		}

		@SuppressWarnings("unused")
		int minor = in.readUnsignedShort();
		
		@SuppressWarnings("unused")
		int major = in.readUnsignedShort();
		
		constPool = new ConstPool(in);
		
		@SuppressWarnings("unused")
		int accessFlags = in.readUnsignedShort();
		
		thisClass = in.readUnsignedShort();
		constPool.setThisClassInfo(thisClass);

		className = constPool.getClassName();
		
		className = className.replaceAll("\\/", "\\.");
	}

}
